package com.zhht.htzx.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;

import com.google.android.material.tabs.TabLayout;
import com.kunminx.architecture.ui.page.DataBindingConfig;
import com.kunminx.architecture.ui.state.State;
import com.kunminx.binding_state.BR;
import com.nsgf.library.data.bean.OrderListBean;
import com.nsgf.library.data.response.ResponseStatus;
import com.nsgf.library.domain.request.AccountRequester;
import com.nsgf.library.ui.adapter.XFragmentAdapter;
import com.nsgf.library.ui.page.BaseActivity;
import com.nsgf.library.ui.page.StateHolder;
import com.nsgf.library.utils.PublicMethodUtils;
import com.zhht.htzx.OrderFragment;
import com.zhht.htzx.R;
import com.zhht.htzx.adapter.OrderAdapter;
import com.zhht.htzx.databinding.ActivityOrderListBinding;

import java.util.ArrayList;
import java.util.List;

/**
 * 订单列表Activity
 */
public class OrderListActivity extends BaseActivity {

    private List<Fragment> fragments = new ArrayList<>();
    private StateHolder mStates;

    private String[] mPageTitleList;

    @Override
    protected void initViewModel() {
        mStates = getActivityScopeViewModel(StateHolder.class);
    }

    @Override
    protected DataBindingConfig getDataBindingConfig() {
        return new DataBindingConfig(R.layout.activity_order_list, BR.vm, mStates);
    }

    private ActivityOrderListBinding mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = (ActivityOrderListBinding) getBinding();
        mStates.titleBar.set("我的订单");
        index = getIntent().getIntExtra("index", 0);
        setupTabLayout();
    }


    private int index = 0;

    private void setupTabLayout() {

        //0:待支付 10:待发货 20:已发货 30:已完成 40:已取消
        fragments.add(OrderFragment.newInstance(""));
        fragments.add(OrderFragment.newInstance("0"));
        fragments.add(OrderFragment.newInstance("10"));
        fragments.add(OrderFragment.newInstance("20"));
        fragments.add(OrderFragment.newInstance("30"));

        mPageTitleList = new String[]{"全部", "待付款", "待发货", "待收货", "已完成"};
        mBinding.viewPager.setOffscreenPageLimit(5);
        XFragmentAdapter adapter = new XFragmentAdapter(this, getSupportFragmentManager(), fragments, mPageTitleList);
        mBinding.viewPager.setAdapter(adapter);

        PublicMethodUtils.initMagicIndicator(mBinding.magicIndicator, mBinding.viewPager, mPageTitleList, this);

        mBinding.viewPager.setCurrentItem(index);
    }


} 